﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class TblLoaiBpbkDAO:IData<TblLoaiBpbk> 
 	{
		public TblLoaiBpbkDAO(String myconnecString) : base(myconnecString) { }

		protected override int InsertOnSubmit(ref TblLoaiBpbk item, int t) {
			 return connec.ExecuteNonQuery("sp_TblLoaiBpbk", CommandType.StoredProcedure,new SqlParameter("@flag", t),
				 new SqlParameter("@" + TblLoaiBpbk.c_MaLoaiBpbk, item.MaLoaiBpbk), new SqlParameter("@" + TblLoaiBpbk.c_TenLoaiBpbk, item.TenLoaiBpbk),
				 new SqlParameter("@" + TblLoaiBpbk.c_DaXoa, item.DaXoa));
		}

		public override TblLoaiBpbk GetItem(IDataReader dr)
		{
			TblLoaiBpbk obj = new TblLoaiBpbk();
			obj.MaLoaiBpbk = Convert.ToInt32(dr[TblLoaiBpbk.c_MaLoaiBpbk]);
			obj.TenLoaiBpbk = Convert.ToString(dr[TblLoaiBpbk.c_TenLoaiBpbk]);
			obj.DaXoa = Convert.ToBoolean(dr[TblLoaiBpbk.c_DaXoa]);
			return obj;
		}

		public override List<TblLoaiBpbk> GetAll()
		{
			return GetAll("sp_GetAllTblLoaiBpbk", CommandType.StoredProcedure);
		}

		public override TblLoaiBpbk GetItemById(object id)
		{
			return GetAll().SingleOrDefault(p => p.MaLoaiBpbk == Convert.ToInt32(id));
		}
		public override TblLoaiBpbk GetItemById(TblLoaiBpbk item){
			throw new NotImplementedException();
		}

	}

 }
